package com.saascloud.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Author: liangxu
 * @Contact: one_dream@aliyun.com
 * @Date: 2022/4/25 11:21
 * @Version: 1.0
 * @Description:
 */
@EnableSwagger2WebMvc
@Profile({"dev","test"}) // pro不生效
public class SwaggerConfiguration {

    @Bean
    public Docket groupName1() {
        return getDocket("API", "demo", "API");
    }

    public Docket getDocket(String groupName, String path, String apiName) {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo(apiName))
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.isoftstone"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(String title) {
        return new ApiInfoBuilder()
                .title(title)
                .version("1.0")
                .build();
    }

}
